package ntd.util.frame.spring.filter;


import cn.hutool.log.StaticLog;
import ntd.tool.abnormal.ComAbnormal;
import ntd.util.config.common.bo.ResponseBO;
import ntd.util.config.common.exception.ComException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Priority;

@ControllerAdvice
@Priority(1)
public class GlobalExceptionHandler {

    @ExceptionHandler(ComException.class)
    @ResponseBody
    public ResponseBO comException(ComException e) {
        return new ResponseBO(e.getCode(), e.getMessage());
    }

    @ExceptionHandler(ComAbnormal.class)
    @ResponseBody
    public ResponseBO comAbnormal(ComAbnormal e) {
        return new ResponseBO(e.getCode(), e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ResponseBO notFount(Exception e) {
        StaticLog.error(e, "[全局异常]");
        return ResponseBO.err(e.getMessage());
    }
}
